const axios = require('axios');

const baseURL = 'http://localhost:7002/api/v1';

// 测试用的token（需要先登录获取）
const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwidXNlcm5hbWUiOiJkZW1vIiwiZW1haWwiOiJkZW1vQGV4YW1wbGUuY29tIiwiaWF0IjoxNzUzMjM0MTc1LCJleHAiOjE3NTM4Mzg5NzV9.eH9yAWLfyrJVCUB-DqhI1Z5aaxtiED72oRZTESf-7Qs';

const api = axios.create({
  baseURL,
  headers: {
    'Authorization': `Bearer ${token}`,
    'Content-Type': 'application/json'
  }
});

async function testRecommendations() {
  console.log('🧪 开始测试推荐功能...\n');

  try {
    // 1. 测试天气推荐 - 雪天
    console.log('1️⃣ 测试天气推荐（雪天）...');
    const weatherRes = await api.get('/recommendation/weather-based', {
      params: { city: '北京', weather: '雪', temperature: -5 }
    });
    console.log(`✅ 雪天推荐成功，获得 ${weatherRes.data.data.recommendations?.length || 0} 个推荐`);
    if (weatherRes.data.data.recommendations?.length > 0) {
      const firstRec = weatherRes.data.data.recommendations[0];
      console.log(`   第一个推荐包含 ${firstRec.items?.length || 0} 件衣服`);
      console.log(`   推荐理由: ${firstRec.reason || '无'}`);
      console.log(`   包含单品: ${firstRec.items?.map(item => item.name).join(', ') || '无'}`);
    }
    console.log('');

    // 1.2 测试天气推荐 - 夏天
    console.log('1️⃣.2 测试天气推荐（夏天）...');
    const summerRes = await api.get('/recommendation/weather-based', {
      params: { city: '北京', weather: '晴', temperature: 35 }
    });
    console.log(`✅ 夏天推荐成功，获得 ${summerRes.data.data.recommendations?.length || 0} 个推荐`);
    if (summerRes.data.data.recommendations?.length > 0) {
      const firstRec = summerRes.data.data.recommendations[0];
      console.log(`   第一个推荐包含 ${firstRec.items?.length || 0} 件衣服`);
      console.log(`   推荐理由: ${firstRec.reason || '无'}`);
      console.log(`   包含单品: ${firstRec.items?.map(item => item.name).join(', ') || '无'}`);
    }
    console.log('');

    // 2. 测试场合推荐 - 约会
    console.log('2️⃣ 测试场合推荐（约会）...');
    const dateRes = await api.get('/recommendation/occasion-based', {
      params: { occasion: 'date', style: 'romantic' }
    });
    console.log(`✅ 约会推荐成功，获得 ${dateRes.data.data.recommendations?.length || 0} 个推荐`);
    if (dateRes.data.data.recommendations?.length > 0) {
      const firstRec = dateRes.data.data.recommendations[0];
      console.log(`   第一个推荐包含 ${firstRec.items?.length || 0} 件衣服`);
      console.log(`   推荐理由: ${firstRec.reason || '无'}`);
      console.log(`   包含单品: ${firstRec.items?.map(item => item.name).join(', ') || '无'}`);
    }
    console.log('');

    // 2.2 测试场合推荐 - 工作
    console.log('2️⃣.2 测试场合推荐（工作）...');
    const workRes = await api.get('/recommendation/occasion-based', {
      params: { occasion: 'work', style: 'business' }
    });
    console.log(`✅ 工作推荐成功，获得 ${workRes.data.data.recommendations?.length || 0} 个推荐`);
    if (workRes.data.data.recommendations?.length > 0) {
      const firstRec = workRes.data.data.recommendations[0];
      console.log(`   第一个推荐包含 ${firstRec.items?.length || 0} 件衣服`);
      console.log(`   推荐理由: ${firstRec.reason || '无'}`);
      console.log(`   包含单品: ${firstRec.items?.map(item => item.name).join(', ') || '无'}`);
    }
    console.log('');

    // 3. 测试颜色推荐 - 单色搭配
    console.log('3️⃣ 测试颜色推荐（黑色单色）...');
    const monoRes = await api.get('/recommendation/color-based', {
      params: { baseColor: '黑色', colorScheme: 'monochromatic' }
    });
    console.log(`✅ 黑色单色推荐成功，获得 ${monoRes.data.data.recommendations?.length || 0} 个推荐`);
    if (monoRes.data.data.recommendations?.length > 0) {
      const firstRec = monoRes.data.data.recommendations[0];
      console.log(`   第一个推荐包含 ${firstRec.items?.length || 0} 件衣服`);
      console.log(`   推荐理由: ${firstRec.reason || '无'}`);
      console.log(`   包含单品: ${firstRec.items?.map(item => `${item.name}(${item.color})`).join(', ') || '无'}`);
    }
    console.log('');

    // 3.2 测试颜色推荐 - 互补色搭配
    console.log('3️⃣.2 测试颜色推荐（蓝色互补）...');
    const compRes = await api.get('/recommendation/color-based', {
      params: { baseColor: '蓝色', colorScheme: 'complementary' }
    });
    console.log(`✅ 蓝色互补推荐成功，获得 ${compRes.data.data.recommendations?.length || 0} 个推荐`);
    if (compRes.data.data.recommendations?.length > 0) {
      const firstRec = compRes.data.data.recommendations[0];
      console.log(`   第一个推荐包含 ${firstRec.items?.length || 0} 件衣服`);
      console.log(`   推荐理由: ${firstRec.reason || '无'}`);
      console.log(`   包含单品: ${firstRec.items?.map(item => `${item.name}(${item.color})`).join(', ') || '无'}`);
    }
    console.log('');

    // 4. 测试今日推荐
    console.log('4️⃣ 测试今日推荐...');
    const todayRes = await api.get('/recommendation/today', {
      params: { city: '北京' }
    });
    console.log(`✅ 今日推荐成功，获得 ${todayRes.data.data.recommendations?.length || 0} 个推荐`);
    if (todayRes.data.data.recommendations?.length > 0) {
      console.log(`   第一个推荐包含 ${todayRes.data.data.recommendations[0].items?.length || 0} 件衣服`);
    }
    console.log('');

    console.log('🎉 所有推荐功能测试完成！');

  } catch (error) {
    console.error('❌ 测试失败:', error.response?.data || error.message);
    if (error.response?.data?.message) {
      console.error('   错误详情:', error.response.data.message);
    }
  }
}

// 运行测试
testRecommendations();
